﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="/CSS/Main.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="/Content/lib/iview/styles/iview.css">
    <script src="/UserCotrols/My97DatePicker/WdatePicker.js"></script>
    <script src="/Content/lib/vue/vue-2.5.17.min.js"></script>
    <script src="/Content/lib/axios/axios.js"></script>
    <script type="text/javascript" src="/Content/lib/iview/iview.min.js"></script>
    <script src="/Scripts/jquery.1.11.1.js"></script>
    <script src="/Scripts/Thk.Utility.js"></script>
    <script src="/Scripts/Thk.Component.js"></script>
    <script type="text/javascript">
        //构造Web程序入口
        window.onload = function () {
            var app = new Vue({
                el: "#app",
                data: {
                    formItem: {
                        BEGIN_DATE: '',
                        OVER_DATE: '',
                        LAST_UPDATE_DATE: null,
                        FORM_COMPANY_ID: null,
                        COMPANY_DATA: [],
                        ACCOUNT_DATA: [],
                        ACCOUNT_ID: null
                    },
                    FORM_DATA: [],
                    LOAD_STATUS: true,
                    All_ACCOUNT: true,
                    JZ: {
                        JZ_DATE: "",
                        CURRENT_PAGE: 1,
                        MAX_SIZE: 1,
                        PAGE_SIZE: 40,
                        LODING: false,
                        DATA: [],
                        COLUMNS: [
                            {
                                type: 'index',
                                title: "序号",
                                align: "center",
                                width: 60,
                                sortable: true
                            }
                            ,
                            {
                                title: "结转日期",
                                key: "CARRY_OVER_MONTH",
                                minWidth: 200,
                                tooltip: true
                            }
                            ,
                            {
                                title: "公司名称",
                                key: "COMAPNY_NAME",
                                minWidth: 200,
                                tooltip: true
                            }
                            ,
                            {
                                title: "操作人",
                                key: "OPEAR_NAME",
                                minWidth: 200
                            },
                            {
                                title: "操作时间",
                                key: "OPEAR_DATE",
                                width: 105,
                                align: "center",
                                render: function (h, params) {
                                    //console.log(params);
                                    var date = new Date(params.row.OPEAR_DATE);
                                    //console.log(params.row.D_TRANDATE);
                                    return h('div', date.format("yyyy-MM-dd"));
                                }
                            }
                        ]
                    }
                },
                methods: {
                    ZQ_CLICK: function () {
                        var that = this;
                        var accountNumber = that.GET_ACCOUNT_NUMBER();
                        if (accountNumber == null) {
                            that.$Modal.info({
                                title: '提示',
                                content: '请选择银行账号'
                            });
                            return;
                        }
                        var beinDate = that.formItem.BEGIN_DATE;
                        if (beinDate == null || beinDate == '') {
                            that.$Modal.info({
                                title: '提示',
                                content: '请选择开始时间'
                            });
                            return;
                        }
                        var overDate = that.formItem.OVER_DATE;
                        if (overDate == null || overDate == '') {
                            that.$Modal.info({
                                title: '提示',
                                content: '请选择结束时间'
                            });
                            return;
                        }
                        if (beinDate > overDate) {
                            that.$Modal.info({
                                title: '提示',
                                content: '开始时间不能大于结束时间'
                            });
                            return;
                        }
                        var data = {};
                        data.ACCOUNT_NUMBER = accountNumber;
                        data.COMPANY_ID = that.formItem.FORM_COMPANY_ID;
                        data.BEGIN_DATE = beinDate.format("yyyy-MM-dd");
                        data.OVER_DATE = overDate.format("yyyy-MM-dd");
                        that.LOAD_STATUS = true;
                        axios.post("/Funds/GetBankListByGS.aspx?TYPE=API", JSON.stringify(data))
                            .then(result => {
                                console.log(result);
                                that.LOAD_STATUS = false;
                                if (result.status != 200 || result.data.Type != 1) {
                                    that.$Modal.info({
                                        title: '提示',
                                        content: `服务异常`
                                    });
                                }
                                else {
                                    that.$Modal.info({
                                        title: '提示',
                                        content: `执行成功`
                                    });
                                }
                            })
                            .catch(result => {
                                that.LOAD_STATUS = false;
                                that.$Modal.info({
                                    title: '提示',
                                    content: `服务异常`
                                });
                            });
                    },
                    COMPANY_CHANGE: function () {
                        var that = this;
                        console.log("xx");
                        if (that.formItem.FORM_COMPANY_ID == null) {

                            return;
                        }
                        that.LOAD_ACCOUNT();
                    },
                    LOAD_ACCOUNT: function () {
                        var that = this;
                        var data = {};
                        data.Type = "GET_BY_CMYID";
                        data.COMPANY_ID = that.formItem.FORM_COMPANY_ID;
                        axios.post("/ParameterSettings/SetBank.aspx?TYPE=API", JSON.stringify(data))
                            .then(result => {
                                that.LOAD_STATUS = false;
                                if (result.status != 200 || result.data.Type != 1) {
                                    that.$Modal.info({
                                        title: '提示',
                                        content: `服务异常`
                                    });
                                }
                                else {
                                    that.formItem.ACCOUNT_DATA = result.data.Data;
                                    if (result.data.Data.length > 0) {
                                        that.formItem.ACCOUNT_ID = result.data.Data[0].Account_Id;
                                    }
                                    else {
                                        that.formItem.ACCOUNT_ID = null;
                                    }
                                }
                            });
                    },
                    LOAD_COMPANY: function () {
                        var that = this;
                        //同步获取
                        var data = top.window.AllCompanyInfo;
                        if (data == undefined) {
                            $.ajax({
                                async: false,
                                url: "/Module/ApplyView/ApplyHandler.ashx?MethodType=AllCompanyInfo",
                                type: "POST",
                                success: function (result) {
                                    //console.log(result);
                                    if (result.Type != 1) {
                                        return;
                                    }
                                    data = result.Data;
                                    top.window.AllCompanyInfo = data;
                                }
                            });
                        }
                        for (var i = 0; i < data.length; i++) {
                            var company = data[i];
                            that.formItem.COMPANY_DATA.push({ Text: company.Name, Value: company.Id });
                        }
                        if (data.length > 0) {
                            that.formItem.FORM_COMPANY_ID = data[0].Id;
                        }
                        else {
                            that.formItem.FORM_COMPANY_ID = null;
                        }
                    },
                    GET_ACCOUNT_NUMBER: function () {
                        var that = this;
                        for (var i = 0; i < that.formItem.ACCOUNT_DATA.length; i++) {
                            if (that.formItem.ACCOUNT_ID == that.formItem.ACCOUNT_DATA[i].Account_Id) {
                                return that.formItem.ACCOUNT_DATA[i].Account_No;
                            }
                        }
                        return null;
                    },
                    QUERY_CLICK: function () {

                    },
                    ADD_CLICK: function () {

                    },
                    JZ_QUERY_CLICK: function (ifFirst) {
                        var that = this;
                        if (that.formItem.FORM_COMPANY_ID == null) {
                            return;
                        }
                        that.PG.LODING = true;
                        if (ifFirst) {
                            that.JZ.CURRENT_PAGE = 1;
                        }
                        //拼接条件
                        var data = {};
                        data.Type = "GET_PAGE";
                        data.COMPANY_ID = that.formItem.FORM_COMPANY_ID;
                        data.PAGE_SIZE = that.JZ.PAGE_SIZE;
                        data.CURRENT_PAGE = that.JZ.CURRENT_PAGE;
                        axios.post("/FUNDS/LOG_JZ.aspx?TYPE=API", JSON.stringify(data))
                            .then(result => {
                                that.JZ.LODING = false;
                                if (result.status != 200) {

                                    return;
                                }
                                console.log(result.data);
                                var data = result.data;
                                if (ifFirst) {
                                    that.JZ.MAX_SIZE = data.Data.Count;
                                }
                                that.JZ.DATA = data.Data.Data;
                            });
                    },
                    JZ_PAGE_SIZE_CHANG: function (size) {
                        //this.FORM_DATA.CURRENT_PAGE = size;
                        //this.SELECT(false);
                        this.JZ.PAGE_SIZE = size;
                        this.JZ_QUERY_CLICK(true);
                    },
                    JZ_PAGE_CHANGE: function (size) {
                        this.JZ.CURRENT_PAGE = size;
                        this.JZ_QUERY_CLICK(false);
                    },
                    JZ_ADD_CLICK: function () {
                        var that = this;
                        if (that.formItem.FORM_COMPANY_ID == "" || that.formItem.FORM_COMPANY_ID == null) {
                            return;
                        }
                        if (that.JZ.JZ_DATE == "" || that.JZ.JZ_DATE == null) {
                            return;
                        }
                        var entity = {};
                        entity.ID = null;
                        entity.COMPANY_ID = that.formItem.FORM_COMPANY_ID;
                        entity.CARRY_OVER_MONTH = that.JZ.JZ_DATE.format("yyyy-MM");
                        var data = {};
                        data.Type = "ADD";
                        data.Data = entity;
                        axios.post("/FUNDS/LOG_JZ.aspx?TYPE=API", JSON.stringify(data))
                            .then(result => {
                                if (result.status != 200) {

                                    return;
                                }
                                that.$Modal.info({
                                    title: '提示',
                                    content: '添加成功'
                                });
                                that.JZ_QUERY_CLICK(false);
                            });
                    }
                },
                mounted: function () {
                    var that = this;
                    that.LOAD_COMPANY();
                    that.formItem.BEGIN_DATE = (new Date()).AddDay(-1);
                    that.formItem.OVER_DATE = new Date();
                    that.LOAD_ACCOUNT();
                    setTimeout(function () {
                        that.LOAD_STATUS = false;
                    }, 500);
                }
            });
        };
    </script>
</head>
<body>
    <div class="Window" style="min-width: 1100px;padding:20px;" id="app">
        <div style="margin:0 auto;width:800px;border:1px solid #0094ff;border-radius:5px;padding:20px;">
            <template>
                <i-form :model="formItem" :label-width="100">
                    <row style="color:#464c5b;font-size:16px;text-align:center;padding-bottom:20px;">
                        抓取工具（工商）
                    </row>
                    <row>
                        <i-col span="12">
                            <form-item label="公司：">
                                <i-select v-model="formItem.FORM_COMPANY_ID" @on-change="COMPANY_CHANGE" placeholder="请选择公司" style="max-width:300px;">
                                    <template v-for="item in formItem.COMPANY_DATA">
                                        <i-option :value="item.Value">{{item.Text}}</i-option>
                                    </template>
                                </i-select>
                            </form-item>
                        </i-col>
                        <i-col span="12">
                            <form-item label="账号：">
                                <i-select v-model="formItem.ACCOUNT_ID" placeholder="请选择账号" style="max-width:300px;">
                                    <template v-for="item in formItem.ACCOUNT_DATA">
                                        <i-option :value="item.Account_Id">({{item.Account_Type==1?"支出户":"收入户"}}){{item.Account_No}}</i-option>
                                    </template>
                                </i-select>
                            </form-item>
                        </i-col>
                    </row>
                    <row>
                        <i-col span="12">
                            <form-item label="起始时间：">
                                <date-picker type="date" placeholder="开始时间" v-model="formItem.BEGIN_DATE" style="margin-right:10px;width:105px;"></date-picker>
                                -
                                <date-picker style="margin-left:10px;width:105px;" type="date" placeholder="结束时间" v-model="formItem.OVER_DATE"></date-picker>
                            </form-item>
                        </i-col>
                    </row>
                    <form-item>
                        <i-col v-if="formItem.LAST_UPDATE_DATE!=null">
                            更新时间:{{formItem.LAST_UPDATE_DATE.ToString()}}
                        </i-col>
                        <i-Button type="primary" @click="ZQ_CLICK">执行</i-Button>
                    </form-item>
                </i-form>
                <Spin size="large" fix v-if="LOAD_STATUS"></Spin>
            </template>
        </div>
        <div style="margin:0 auto;width:800px;border:1px solid #0094ff;border-radius:5px;padding:20px;margin-top:20px;">
            <template>
                <i-form :model="formItem" :label-width="100">
                    <row style="color:#464c5b;font-size:16px;text-align:center;padding-bottom:20px;">
                        自动抓取(队列)（工商）
                    </row>
                    <row>
                        <i-col span="12">
                            <form-item label="公司：">
                                <i-select v-model="formItem.FORM_COMPANY_ID" @on-change="COMPANY_CHANGE" placeholder="请选择公司" style="max-width:300px;">
                                    <template v-for="item in formItem.COMPANY_DATA">
                                        <i-option :value="item.Value">{{item.Text}}</i-option>
                                    </template>
                                </i-select>
                            </form-item>
                        </i-col>
                        <i-col span="12">
                            <form-item label="账号：">
                                <i-select v-model="formItem.ACCOUNT_ID" placeholder="请选择账号" style="max-width:300px;">
                                    <template v-for="item in formItem.ACCOUNT_DATA">
                                        <i-option :value="item.Account_Id">({{item.Account_Type==1?"支出户":"收入户"}}){{item.Account_No}}</i-option>
                                    </template>
                                </i-select>
                            </form-item>
                        </i-col>
                    </row>
                    <row>
                        <i-col span="12">
                            <form-item label="起始时间：">
                                <date-picker type="date" placeholder="开始时间" v-model="formItem.BEGIN_DATE" style="margin-right:10px;width:105px;"></date-picker>
                                -
                                <date-picker style="margin-left:10px;width:105px;" type="date" placeholder="结束时间" v-model="formItem.OVER_DATE"></date-picker>
                            </form-item>
                        </i-col>
                    </row>
                    <row>
                        <i-col span="12">
                            <form-item label="所有账号：">
                                <i-switch v-model="All_ACCOUNT" size="large">
                                    <span slot="open">确定</span>
                                    <span slot="close">关闭</span>
                                </i-switch>
                            </form-item>
                        </i-col>
                    </row>
                    <form-item>
                        <i-col v-if="formItem.LAST_UPDATE_DATE!=null">
                            更新时间:{{formItem.LAST_UPDATE_DATE.ToString()}}
                        </i-col>
                        <i-Button type="primary" @click="QUERY_CLICK">查询</i-Button>
                        <i-Button type="success" style="margin-left:20px;" @click="ADD_CLICK">添加</i-Button>
                    </form-item>
                </i-form>
                <row v-if="FORM_DATA.length>0">
                    <i-table data="FORM_DATA" stripe>
                    </i-table>
                </row>
                <Spin size="large" fix v-if="LOAD_STATUS"></Spin>
            </template>
        </div>
        <div style="margin:0 auto;width:800px;border:1px solid #0094ff;border-radius:5px;padding:20px;margin-top:20px;display:none;">
            <template>
                <i-form :label-width="100">
                    <row style="color:#464c5b;font-size:16px;text-align:center;padding-bottom:20px;">
                        月末结转（收入）
                    </row>
                    <row>
                        <i-col span="12">
                            <form-item label="公司：">
                                <i-select v-model="formItem.FORM_COMPANY_ID" @on-change="COMPANY_CHANGE" placeholder="请选择公司" style="max-width:300px;">
                                    <template v-for="item in formItem.COMPANY_DATA">
                                        <i-option :value="item.Value">{{item.Text}}</i-option>
                                    </template>
                                </i-select>
                            </form-item>
                        </i-col>
                        <i-col span="12">
                            <form-item label="结转周期(月)：">
                                <date-picker type="month" placeholder="请选择月份" format="yyyy-MM" v-model="JZ.JZ_DATE" style="margin-right:10px;width:105px;"></date-picker>
                            </form-item>
                        </i-col>
                    </row>
                    <form-item>
                        <i-Button type="primary" @click="JZ_QUERY_CLICK(true)">查询</i-Button>
                        <i-Button type="success" style="margin-left:20px;" @click="ADD_CLICK">进行结转</i-Button>
                    </form-item>
                </i-form>
                <row v-if="JZ.DATA.length>0" style="border-top:1px solid #0094ff;padding-top:20px;">
                    <i-table :loading="JZ.LODING" :data="JZ.DATA" size="small" border :columns="JZ.COLUMNS">
                    </i-table>
                    <Page style="margin-top:20px;" show-sizer :total="JZ.MAX_SIZE" :page-size="JZ.PAGE_SIZE" :current="JZ.CURRENT_PAGE" @on-page-size-change="JZ_PAGE_SIZE_CHANG" @on-change="JZ_PAGE_CHANGE" />
                </row>
                <Spin size="large" fix v-if="LOAD_STATUS"></Spin>
            </template>
        </div>
    </div>
</body>
</html>